<?php

/**
 * report actions.
 *
 * @package    sf_sandbox
 * @subpackage report
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 2692 2006-11-15 21:03:55Z fabien $
 */
class reportActions extends sfActions
{
    /**
     * Executes index action
     *
     */
    public function executeIndex()
    {
        return $this->redirect('/report/dailyReport');
    }
    public function executeDailyReport()
    {
        $this->getUser()->setAttribute(Globals::SESSION_MAIN_MENU, "REPORT");
        $this->getUser()->setAttribute(Globals::SESSION_SUB_MENU, "DAILY_REPORT");

        $c = new Criteria();
        $c->addAscendingOrderByColumn(MlmRoiDividendPeer::DIVIDEND_DATE);
        $this->mlmRoiDividends = MlmRoiDividendPeer::doSelect($c);
    }
    public function executeMonthlyReport()
    {
        $this->getUser()->setAttribute(Globals::SESSION_MAIN_MENU, "REPORT");
        $this->getUser()->setAttribute(Globals::SESSION_SUB_MENU, "MONTHLY_REPORT");
    }
    public function executeManipulateBonus()
    {


        print_r("Done");
        return sfView::HEADER_ONLY;
    }
    public function executeManipulateRandom()
    {
        $physicalDirectory = sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR . "random.xls";

        error_reporting(E_ALL ^ E_NOTICE);
        require_once 'excel_reader2.php';
        $data = new Spreadsheet_Excel_Reader($physicalDirectory);

        $totalRow = $data->rowcount($sheet_index = 0);
        for ($x = $totalRow; $x > 0; $x--) {
            $date = $data->val($x, "A");
            $operationAmount = $data->val($x, "B");
            $operationRate = $data->val($x, "C");
            $operationProfit = $data->val($x, "D");

            $mlmDailyFundReport = new MlmDailyFundReport();
            $mlmDailyFundReport->setReportDate($date);
            $mlmDailyFundReport->setOperationRate($operationRate);
            $mlmDailyFundReport->setCreatedBy($this->getUser()->getAttribute(Globals::SESSION_USERID, Globals::SYSTEM_USER_ID));
            $mlmDailyFundReport->setUpdatedBy($this->getUser()->getAttribute(Globals::SESSION_USERID, Globals::SYSTEM_USER_ID));
            $mlmDailyFundReport->save();

            $mlmRoiRandom = new MlmRoiRandom();
            $mlmRoiRandom->setOperationRate($operationRate);
            $mlmRoiRandom->setCreatedBy($this->getUser()->getAttribute(Globals::SESSION_USERID, Globals::SYSTEM_USER_ID));
            $mlmRoiRandom->setUpdatedBy($this->getUser()->getAttribute(Globals::SESSION_USERID, Globals::SYSTEM_USER_ID));
            $mlmRoiRandom->save();

            $mlmRoiDividend = new MlmRoiDividend();
            $mlmRoiDividend->setDistId(1);
            $mlmRoiDividend->setReportId($mlmDailyFundReport->getDailyId());
            $mlmRoiDividend->setMt4UserName("8003333");
            //$mlmRoiDividend->setAccountLedgerId("");
            $mlmRoiDividend->setDividendDate($date);
            $mlmRoiDividend->setPackageId(1);
            $mlmRoiDividend->setPackagePrice(1000000);
            $mlmRoiDividend->setRoiPercentage($operationRate);
            $mlmRoiDividend->setMt4Balance($operationAmount);
            $mlmRoiDividend->setDividendAmount($operationProfit);
            $mlmRoiDividend->setStatusCode(Globals::STATUS_SUCCESS);
            $mlmRoiDividend->setCreatedBy($this->getUser()->getAttribute(Globals::SESSION_USERID, Globals::SYSTEM_USER_ID));
            $mlmRoiDividend->setUpdatedBy($this->getUser()->getAttribute(Globals::SESSION_USERID, Globals::SYSTEM_USER_ID));
            $mlmRoiDividend->save();
        }
        print_r("Done");
        return sfView::HEADER_ONLY;
    }
}
